<template>
	<view class="index">
		<musichead title='网易云音乐' :icon='true'></musichead>
		<view class="container">
			<scroll-view scroll-y="true">
				<view class="index-search" style="background-color: #f0f0f0"  @tap="handleToSearch">
					<text class="iconfont iconsearch"></text>
					<input type="text" placeholder="搜索歌曲" @input>
				</view>
				<!-- 骨架屏 -->
				<view v-if="isLoading">
					<mySkeleton :avatarSize="200" :row="3" :loading="isLoading" isarc="square" v-for="(item,key) in 4"
						:titleStyle="{}" :key="key"> </mySkeleton>
				</view>
				<view class="index-list" v-else>
					<view class="index-list-item" v-for="(item,index) in topList" :key="index"
						@tap="handleToList(item.id)">
						<view class="index-list-img">
							<image :src="item.coverImgUrl" alt="">
								<text>{{item.updateFrequency}}</text>
						</view>
						<view class="index-item-text">
							<view v-for="(music,i) in item.tracks" :key="i">
								{{i+1}}.{{music.first}} - {{music.second}}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import '@/common/iconfont.css'
	import {
		topList
	} from '@/common/api.js'
	import mySkeleton from "@/components/myskeleton/myskeleton.vue"
	export default {
		data() {
			return {
				topList: [],
				isLoading:true,

			}
		},
		components: {
			mySkeleton
		},
		onLoad() {
			topList().then((res) => {
				console.log(res)
				if (res.length) {
					this.topList = res
					this.isLoading = false;

				}
			})
		},
		methods: {
			handleToList(id) {
				uni.navigateTo({
					url: '/pages/list/list?listId=' + id,
					success: () => {},
					fail: () => {},
					complete: () => {}
				});
			},
			handleToSearch(){
				uni.navigateTo({
					url: '/pages/search/search',
				});
			}
		}
	}
</script>
<style scoped>
	.index-search {
		display: flex;
		align-items: center;
		height: 70rpx;
		margin: 70rpx 30rpx 30rpx 30rpx;
		border-radius: 50rpx;
		/* background-color: aquamarine; */
	}

	.index-search text {
		font-size: 26rpx;
		margin-right: 26rpx;
		margin-left: 28rpx;
	}

	..index-search input {
		font-size: 28rpx;
		/* 左侧固定，右侧自适应 */
		flex: 1;
	}

	.index-list {
		margin: 0 30rpx;
	}

	.index-list-item {
		display: flex;
		margin-bottom: 34rpx;
	}

	.index-list-img {
		width: 212rpx;
		height: 212rpx;
		position: relative;
		border-radius: 30rpx;
		overflow: hidden;
	}

	.index-list-img image {
		width: 100%;
		height: 100%;
	}

	.index-list-img text {
		position: absolute;
		left: 12rpx;
		bottom: 16rpx;
		color: white;
		font-size: 20rpx;
	}

	.index-item-text {
		width: calc(100% - 212rpx);
		font-size: 24rpx;
	}

	.index-item-text view {
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		word-break: break-all;
		width: 100%;
		line-height: 66rpx;
		margin-left: 20rpx;
	}
</style>
